﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace OpenNETCF.Bookshare.Services
{
    internal class RequestParameterCollection : IEnumerable<RequestParameter>
    {
        private Dictionary<string, RequestParameter> m_parameters;

        public RequestParameterCollection()
        {
            m_parameters = new Dictionary<string, RequestParameter>();
        }

        public IEnumerator<RequestParameter> GetEnumerator()
        {
            return m_parameters.Values.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return m_parameters.Values.GetEnumerator();
        }

        public void Add(RequestParameter parameter)
        {
            m_parameters.Add(parameter.Name, parameter);
        }

        public void Add(string parameterName, string parameterValue)
        {
            Add(new RequestParameter { Name = parameterName, Value = parameterValue });
        }

        public bool ContainsParameter(string name)
        {
            return m_parameters.ContainsKey(name);
        }

        public RequestParameter this[string name]
        {
            get { return m_parameters.FirstOrDefault(p => p.Value.Name == name).Value; }
        }
    }

    internal class RequestParameter
    {
        public string Name { get; set; }
        public string Value { get; set; }
    }
}
